package main;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.text.DecimalFormat;
import java.util.ArrayList;

public class Room {
	private String roomID;
	private String creator;
	private int currentUserAmount = 0;
	
	private ArrayList<String> clientList = new ArrayList<String>();
	private ArrayList<Socket> clientSocketList = new ArrayList<Socket>();
	private ArrayList<ObjectInputStream> clientSocketInputStreamList = new ArrayList<ObjectInputStream>();
	private ArrayList<ObjectOutputStream> clientSocketOutputStreamList = new ArrayList<ObjectOutputStream>();
	
	private static final String CURRENTUSERAMOUNT_FORMAT = "00";
	
	public Room(String roomID, String creator) {
		super();
		this.roomID = roomID;
		this.creator = creator;
		this.currentUserAmount = 0;
	}

	public String getRoomID() {
		return roomID;
	}

	public void setRoomID(String roomID) {
		this.roomID = roomID;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	public int getCurrentUserAmount() {
		return currentUserAmount;
	}

	public void setCurrentUserAmount(int currentUserAmount) {
		this.currentUserAmount = currentUserAmount;
	}
	
	
	public ArrayList<String> getClientList() {
		return clientList;
	}

	public ArrayList<Socket> getClientSocketList() {
		return clientSocketList;
	}

	public static String getCurrentuseramountFormat() {
		return CURRENTUSERAMOUNT_FORMAT;
	}

	public ArrayList<ObjectInputStream> getClientSocketInputStreamList() {
		return clientSocketInputStreamList;
	}

	public ArrayList<ObjectOutputStream> getClientSocketOutputStreamList() {
		return clientSocketOutputStreamList;
	}

	public String getRoomInfo() {
		DecimalFormat df = new DecimalFormat(CURRENTUSERAMOUNT_FORMAT);
		return roomID + creator + df.format(currentUserAmount);
	}
	
	public void addClientSocket(Socket clientSocket, ObjectInputStream objectInputStream, ObjectOutputStream objectOutputStream){
		clientSocketList.add(clientSocket);
		clientSocketInputStreamList.add(objectInputStream);
		clientSocketOutputStreamList.add(objectOutputStream);
	}
	
	public void addClient(String userID){
		clientList.add(userID);
		currentUserAmount++;
	}
	
	public String getRoomDetailedInfo(){
		String result = roomID+ currentUserAmount;
		for (int i = 0; i< clientList.size(); i++)
			result += clientList.get(i);
		return result;
	}
	
}
